//
//  LGGroupChatMemberController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/27.
//  群聊成员

#import "LGGroupChatMemberController.h"

//患者详情 - 癌症 - 圆荷健康
#import "LGPatientDetailController_YHJK.h"
#import "LGPatientDetailController2.h"

//医生详情
#import "LGPersionalDataController.h"

#import "LGGroupChatMemberCell.h"
@interface LGGroupChatMemberController ()<UICollectionViewDataSource,UICollectionViewDelegate>

/**   */
@property (nonatomic , strong)UICollectionView *collectionView;
/**   */
@property (nonatomic , strong)NSMutableArray *dataArray;

@end

@implementation LGGroupChatMemberController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"查看成员";
    [self.view addSubview:self.collectionView];
    [self emptyViewWithSuperView:self.collectionView frame:self.collectionView.bounds];
    [self requestData];
}

-(void)requestData{
    NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:@{@"im_group_id":self.groupId}];
    if(_appointId && _appointId.length>0){
        [tempDic setValue:self.appointId forKey:@"appointment_id"];
    }
    [RequestUtil withPOST:@"/doctor/im/groupMemberList" parameters:tempDic withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(code == 200){
            self.dataArray = [NSMutableArray array];
            [self.dataArray addObjectsFromArray:returnData[@"patients"]];
            [self.dataArray addObjectsFromArray:returnData[@"doctors"]];
            [self.collectionView reloadData];
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无成员" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:LGErrorMessage offset:0];
        }
    }];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    LGGroupChatMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.dataDic = self.dataArray[indexPath.item];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.item];
    if([tempDic.allKeys containsObject:@"patient_id"]){
        //患者详情
        NSString *nodePage = LGNSString(tempDic[@"nodepage"]);
        if ([nodePage isEqualToString:@"1"]) {
            //市一慢阻肺
            LGPatientDetailController2 *controller = [[LGPatientDetailController2 alloc]init];
            controller.patientid = LGNSString(tempDic[@"patient_id"]);
            controller.levelid = LGNSString(tempDic[@"level_id"]);
            controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
            [self.navigationController pushViewController:controller animated:YES];
        }else{
            //其他
            LGPatientDetailController_YHJK *controller = [[LGPatientDetailController_YHJK alloc]init];
            controller.patientid = LGNSString(tempDic[@"patient_id"]);
            controller.levelid = LGNSString(tempDic[@"level_id"]);
            controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
            [self.navigationController pushViewController:controller animated:YES];
        }
       
    }else{
        //医生
        LGPersionalDataController *controller = [[LGPersionalDataController alloc]init];
        controller.userId = LGNSString(tempDic[@"id"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}

-(UICollectionView *)collectionView{
    if(!_collectionView){
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.itemSize = CGSizeMake((Screen_W-viewPix(48))/5.0-1, viewPix(93));
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(32), Screen_H-topBarHeight-viewPix(40)-bottomSafeBarHeight/2.0) collectionViewLayout:layout];
        [_collectionView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        [_collectionView registerClass:[LGGroupChatMemberCell class] forCellWithReuseIdentifier:@"cell"];
        _collectionView.contentInset = UIEdgeInsetsMake(viewPix(8), viewPix(8), viewPix(8), viewPix(8));
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.dataSource = self;
        _collectionView .delegate = self;
    }
    return _collectionView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
